package com.gzz.orchid.common.core.support;

/**
 * 统一响应信息
 *
 * @param <T>
 * @author higmd
 */
public class R<T> {
    /**
     * 响应码
     */
    private final int code;
    /**
     * 提示信息
     */
    private String message;
    /**
     * 具体内容
     */
    private T data;

    private R(int code, String message) {
        this.code = code;
        this.message = message;
    }

    private R(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> R<T> ok(T data) {
        return new R<>(200, "成功", data);
    }

    public static R<Object> ok() {
        return new R<>(200, "成功");
    }

    public static <T> R<T> fail(T data) {
        return new R<>(500, "成功", data);
    }

    public static R<Object> fail() {
        return new R<>(500, "失败");
    }

    public T getData() {
        return this.data;
    }

    public String getMessage() {
        return this.message;
    }

    public int getCode() {
        return this.code;
    }

    public R<T> data(T data) {
        this.data = data;
        return this;
    }

    public R<T> message(String message) {
        this.message = message;
        return this;
    }
}
